﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace StreetSmartAdmin
{
    public partial class TRU : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void DupButton_Click(object sender, EventArgs e)
        {
            string FirstName = ((TextBox)DetailsView1.FindControl("FirstName")).Text;
            string LastName = ((TextBox)DetailsView1.FindControl("LastName")).Text;
            string CompanyName = ((TextBox)DetailsView1.FindControl("CompanyName")).Text;
            string CompanyABN = ((TextBox)DetailsView1.FindControl("CompanyABN")).Text;
            string Street = ((TextBox)DetailsView1.FindControl("Street")).Text;
            string Suburb = ((TextBox)DetailsView1.FindControl("Suburb")).Text;
            string StateName = ((TextBox)DetailsView1.FindControl("StateName")).Text;
            string Postcode = ((TextBox)DetailsView1.FindControl("Postcode")).Text;
            string Phone = ((TextBox)DetailsView1.FindControl("Phone")).Text;
            string Mobile = ((TextBox)DetailsView1.FindControl("Mobile")).Text;
            string Email = ((TextBox)DetailsView1.FindControl("Email")).Text;
            string Comments = ((TextBox)DetailsView1.FindControl("Comments")).Text;
            string CurrentProvider = ((TextBox)DetailsView1.FindControl("CurrentProvider")).Text;
            string PromotionCode = ((TextBox)DetailsView1.FindControl("PromotionCode")).Text;
            string AdminFee = ((TextBox)DetailsView1.FindControl("AdminFee")).Text;
            string LeadSource = ((TextBox)DetailsView1.FindControl("LeadSource")).Text;
            string TypeOrg = ((TextBox)DetailsView1.FindControl("TypeOrg")).Text;
            string PreferredDay = ((TextBox)DetailsView1.FindControl("PreferredDay")).Text;
            string PreferredTime = ((TextBox)DetailsView1.FindControl("PreferredTime")).Text;
            string TotalSites = ((TextBox)DetailsView1.FindControl("TotalSites")).Text;
            string ElecTotalAnnualSpend = ((TextBox)DetailsView1.FindControl("ElecTotalAnnualSpend")).Text;
            string GasTotalAnnualSpend = ((TextBox)DetailsView1.FindControl("GasTotalAnnualSpend")).Text;
            string TotalAnnualSpend = ((TextBox)DetailsView1.FindControl("TotalAnnualSpend")).Text;
            string AccountStatus = ((TextBox)DetailsView1.FindControl("AccountStatus")).Text;
            string StatusName = ((TextBox)DetailsView1.FindControl("StatusName")).Text;
            string AccountStatusHistory = ((TextBox)DetailsView1.FindControl("AccountStatusHistory")).Text;
            string SourceCode = ((TextBox)DetailsView1.FindControl("SourceCode")).Text;
            string OperatorSSE = ((TextBox)DetailsView1.FindControl("OperatorSSE")).Text;
            string VendorID = ((TextBox)DetailsView1.FindControl("VendorID")).Text;
            string DateConverted = ((TextBox)DetailsView1.FindControl("DateConverted")).Text;
            string MoverSwicher = ((TextBox)DetailsView1.FindControl("MoverSwicher")).Text;
            string RESI_SME = ((TextBox)DetailsView1.FindControl("RESI_SME")).Text;
            string ElectricityConversion = ((TextBox)DetailsView1.FindControl("ElectricityConversion")).Text;
            string GasConversion = ((TextBox)DetailsView1.FindControl("GasConversion")).Text;
            string MoveInDate = ((TextBox)DetailsView1.FindControl("MoveInDate")).Text;
            string ID_Type = ((TextBox)DetailsView1.FindControl("ID_Type")).Text;
            string ID_Number = ((TextBox)DetailsView1.FindControl("ID_Number")).Text;
            string ID_Expiry = ((TextBox)DetailsView1.FindControl("ID_Expiry")).Text;
            string FirstAccountHolderTitle = ((TextBox)DetailsView1.FindControl("FirstAccountHolderTitle")).Text;
            string FirstAccountHolderFirstName = ((TextBox)DetailsView1.FindControl("FirstAccountHolderFirstName")).Text;
            string FirstAccountHolderSurname = ((TextBox)DetailsView1.FindControl("FirstAccountHolderSurname")).Text;
            string FirstAccountHolderDOB = ((TextBox)DetailsView1.FindControl("FirstAccountHolderDOB")).Text;
            string SecondAccountHolderTitle = ((TextBox)DetailsView1.FindControl("SecondAccountHolderTitle")).Text;
            string SecondAccountHolderFirstName = ((TextBox)DetailsView1.FindControl("SecondAccountHolderFirstName")).Text;
            string SecondAccountHolderSurname = ((TextBox)DetailsView1.FindControl("SecondAccountHolderSurname")).Text;
            string SecondAccountHolderDOB = ((TextBox)DetailsView1.FindControl("SecondAccountHolderDOB")).Text;
            string SupplyAddress = ((TextBox)DetailsView1.FindControl("SupplyAddress")).Text;
            string SupplyAddressSuburb = ((TextBox)DetailsView1.FindControl("SupplyAddressSuburb")).Text;
            string SupplyAddressState = ((TextBox)DetailsView1.FindControl("SupplyAddressState")).Text;
            string SupplyAddressPostcode = ((TextBox)DetailsView1.FindControl("SupplyAddressPostcode")).Text;
            string TenantOwner = ((TextBox)DetailsView1.FindControl("TenantOwner")).Text;
            string Elec = ((TextBox)DetailsView1.FindControl("Elec")).Text;
            string Gas = ((TextBox)DetailsView1.FindControl("Gas")).Text;
            string ProductType = ((TextBox)DetailsView1.FindControl("ProductType")).Text;
            string NoOfPeopleInHouse = ((TextBox)DetailsView1.FindControl("NoOfPeopleInHouse")).Text;
            string ConcessionCardType = ((TextBox)DetailsView1.FindControl("ConcessionCardType")).Text;
            string ConcessionCardEntitlement = ((TextBox)DetailsView1.FindControl("ConcessionCardEntitlement")).Text;
            string ConcessionCardNo = ((TextBox)DetailsView1.FindControl("ConcessionCardNo")).Text;
            string ConcessionCardExp = ((TextBox)DetailsView1.FindControl("ConcessionCardExp")).Text;
            string NameOnConcessionCard = ((TextBox)DetailsView1.FindControl("NameOnConcessionCard")).Text;
            string AnyHazards = ((TextBox)DetailsView1.FindControl("AnyHazards")).Text;
            string AnyAccessRequirements = ((TextBox)DetailsView1.FindControl("AnyAccessRequirements")).Text;
            string SpecialInstructionsForAccess = ((TextBox)DetailsView1.FindControl("SpecialInstructionsForAccess")).Text;
            string AdvisedMainSwitchNeedsTurningOff = ((TextBox)DetailsView1.FindControl("AdvisedMainSwitchNeedsTurningOff")).Text;
            string SafetyCertificateRequired = ((TextBox)DetailsView1.FindControl("SafetyCertificateRequired")).Text;
            string ElecStatus = ((TextBox)DetailsView1.FindControl("ElecStatus")).Text;
            string GasStatus = ((TextBox)DetailsView1.FindControl("GasStatus")).Text;
            string Reason = ((TextBox)DetailsView1.FindControl("Reason")).Text;
            string ExistingTRUEnergyCustomer = ((TextBox)DetailsView1.FindControl("ExistingTRUEnergyCustomer")).Text;
            string AdditionalQuestion = ((TextBox)DetailsView1.FindControl("AdditionalQuestion")).Text;
            string SSE_Operator_Feedback = ((TextBox)DetailsView1.FindControl("SSE_Operator_Feedback")).Text;
            string NewProvider = ((TextBox)DetailsView1.FindControl("NewProvider")).Text;
            string InsertCommandFeild = "INSERT INTO tbluser (FirstName,LastName,Email,CompanyName,CompanyABN,Street,Suburb,StateName,Postcode,Phone,Mobile,CurrentProvider,PromotionCode,AdminFee,Comments,LeadSource,TypeOrg,PreferredDay,PreferredTime,TotalSites,ElecTotalAnnualSpend,GasTotalAnnualSpend,TotalAnnualSpend,AccountStatus,StatusName,AccountStatusHistory,SourceCode,OperatorSSE,VendorID,DateConverted,MoverSwicher,RESI_SME,ElectricityConversion,GasConversion,MoveInDate,ID_Type,ID_Number,ID_Expiry,FirstAccountHolderTitle,FirstAccountHolderFirstName,FirstAccountHolderSurname,FirstAccountHolderDOB,SecondAccountHolderTitle,SecondAccountHolderFirstName,SecondAccountHolderSurname,SecondAccountHolderDOB,SupplyAddress,SupplyAddressSuburb,SupplyAddressState,SupplyAddressPostcode,TenantOwner,Elec,Gas,ProductType,NoOfPeopleInHouse,ConcessionCardType,ConcessionCardEntitlement,ConcessionCardNo,ConcessionCardExp,NameOnConcessionCard,AnyHazards,AnyAccessRequirements,SpecialInstructionsForAccess,AdvisedMainSwitchNeedsTurningOff,SafetyCertificateRequired,ElecStatus,GasStatus,Reason,ExistingTRUEnergyCustomer,SSE_Operator_Feedback,NewProvider) values";
            string InsertCommandValue = "('" + FirstName + "','" + LastName + "','" + Email + "','" + CompanyName + "','" + CompanyABN + "','" + Street + "','" + Suburb + "','" + StateName + "','" + Postcode + "','" + Phone + "','" + Mobile + "','" + CurrentProvider + "','" + PromotionCode + "','" + AdminFee + "','" + Comments + "','" + LeadSource + "','" + TypeOrg + "','" + PreferredDay + "','" + PreferredTime + "','" + TotalSites + "','" + ElecTotalAnnualSpend + "','" + GasTotalAnnualSpend + "','" + TotalAnnualSpend + "','" + AccountStatus + "','" + StatusName + "','" + AccountStatusHistory + "','" + SourceCode + "','" + OperatorSSE + "','" + VendorID + "','" + DateConverted + "','" + MoverSwicher + "','" + RESI_SME + "','" + ElectricityConversion + "','" + GasConversion + "','" + MoveInDate + "','" + ID_Type + "','" + ID_Number + "','" + ID_Expiry + "','" + FirstAccountHolderTitle + "','" + FirstAccountHolderFirstName + "','" + FirstAccountHolderSurname + "','" + FirstAccountHolderDOB + "','" + SecondAccountHolderTitle + "','" + SecondAccountHolderFirstName + "','" + SecondAccountHolderSurname + "','" + SecondAccountHolderDOB + "','" + SupplyAddress + "','" + SupplyAddressSuburb + "','" + SupplyAddressState + "','" + SupplyAddressPostcode + "','" + TenantOwner + "','" + Elec + "','" + Gas + "','" + ProductType + "','" + NoOfPeopleInHouse + "','" + ConcessionCardType + "','" + ConcessionCardEntitlement + "','" + ConcessionCardNo + "','" + ConcessionCardExp + "','" + NameOnConcessionCard + "','" + AnyHazards + "','" + AnyAccessRequirements + "','" + SpecialInstructionsForAccess + "','" + AdvisedMainSwitchNeedsTurningOff + "','" + SafetyCertificateRequired + "','" + ElecStatus + "','" + GasStatus + "','" + Reason + "','" + ExistingTRUEnergyCustomer + "','" + SSE_Operator_Feedback + "','" + NewProvider + "');";
            insertUser(InsertCommandFeild + InsertCommandValue);
        }

        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            String miss = "";
            if (((TextBox)DetailsView1.FindControl("StatusName")).Text.Equals("Converted"))
            {
                if (((TextBox)DetailsView1.FindControl("TypeOrg")).Text.Equals("RESI"))
                {
                    if (((TextBox)DetailsView1.FindControl("TotalSites")).Text.Equals(""))
                        miss = miss + "TotalSites \\n";
                    if (((TextBox)DetailsView1.FindControl("SourceCode")).Text.Equals(""))
                        miss = miss + "SourceCode \\n";
                    if (((TextBox)DetailsView1.FindControl("ProductType")).Text.Equals(""))
                        miss = miss + "ProductType \\n";
                    if (((TextBox)DetailsView1.FindControl("MoverSwicher")).Text.Equals(""))
                        miss = miss + "MoverSwicher \\n";
                    if (((TextBox)DetailsView1.FindControl("MoverSwicher")).Text.Equals("Mover"))
                    {
                        if (((TextBox)DetailsView1.FindControl("MoveInDate")).Text.Equals(""))
                            miss = miss + "MoveInDate \\n";
                    }
                    if (((TextBox)DetailsView1.FindControl("RESI_SME")).Text.Equals(""))
                        miss = miss + "RESI_SME \\n";
                    if (((TextBox)DetailsView1.FindControl("ElectricityConversion")).Text.Equals(""))
                        miss = miss + "ElectricityConversion \\n";
                    if (((TextBox)DetailsView1.FindControl("GasConversion")).Text.Equals(""))
                        miss = miss + "GasConversion \\n";
                    if (((TextBox)DetailsView1.FindControl("ID_Type")).Text.Equals(""))
                        miss = miss + "ID_Type \\n";
                    if (((TextBox)DetailsView1.FindControl("ID_Number")).Text.Equals(""))
                        miss = miss + "ID_Number \\n";
                    if (((TextBox)DetailsView1.FindControl("FirstAccountHolderTitle")).Text.Equals(""))
                        miss = miss + "FirstAccountHolderTitle \\n";
                    if (((TextBox)DetailsView1.FindControl("FirstAccountHolderFirstName")).Text.Equals(""))
                        miss = miss + "FirstAccountHolderFirstName \\n";
                    if (((TextBox)DetailsView1.FindControl("FirstAccountHolderSurname")).Text.Equals(""))
                        miss = miss + "FirstAccountHolderSurname \\n";
                    if (((TextBox)DetailsView1.FindControl("FirstAccountHolderDOB")).Text.Equals(""))
                        miss = miss + "FirstAccountHolderDOB \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddress")).Text.Equals(""))
                        miss = miss + "SupplyAddress \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddressSuburb")).Text.Equals(""))
                        miss = miss + "SupplyAddressSuburb \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddressState")).Text.Equals(""))
                        miss = miss + "SupplyAddressState \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddressPostcode")).Text.Equals(""))
                        miss = miss + "SupplyAddressPostcode \\n";
                    if (((TextBox)DetailsView1.FindControl("TenantOwner")).Text.Equals(""))
                        miss = miss + "TenantOwner \\n";
                    if (((TextBox)DetailsView1.FindControl("Elec")).Text.Equals(""))
                        miss = miss + "Elec \\n";
                    if (((TextBox)DetailsView1.FindControl("Gas")).Text.Equals(""))
                        miss = miss + "Gas \\n";
                    if (((TextBox)DetailsView1.FindControl("ExistingTRUEnergyCustomer")).Text.Equals(""))
                        miss = miss + "ExistingTRUEnergyCustomer \\n";

                    if (miss.Equals(""))
                        DetailsView1.UpdateItem(false);
                    else
                    {
                        MessageBox("The following fields must be completed:\\n" + miss);
                        DetailsView1.UpdateItem(false);
                    }
                }

                if (((TextBox)DetailsView1.FindControl("TypeOrg")).Text.Equals("SME"))
                {
                    if (((TextBox)DetailsView1.FindControl("CompanyName")).Text.Equals(""))
                        miss = miss + "CompanyName \\n";
                    if (((TextBox)DetailsView1.FindControl("CompanyABN")).Text.Equals(""))
                        miss = miss + "CompanyABN \\n";
                    if (((TextBox)DetailsView1.FindControl("TotalSites")).Text.Equals(""))
                        miss = miss + "TotalSites \\n";
                    if (((TextBox)DetailsView1.FindControl("SourceCode")).Text.Equals(""))
                        miss = miss + "SourceCode \\n";
                    if (((TextBox)DetailsView1.FindControl("ProductType")).Text.Equals(""))
                        miss = miss + "ProductType \\n";
                    if (((TextBox)DetailsView1.FindControl("MoverSwicher")).Text.Equals(""))
                        miss = miss + "MoverSwicher \\n";
                    if (((TextBox)DetailsView1.FindControl("MoverSwicher")).Text.Equals("Mover"))
                    {
                        if (((TextBox)DetailsView1.FindControl("MoveInDate")).Text.Equals(""))
                            miss = miss + "MoveInDate \\n";
                    }
                    if (((TextBox)DetailsView1.FindControl("RESI_SME")).Text.Equals(""))
                        miss = miss + "RESI_SME \\n";
                    if (((TextBox)DetailsView1.FindControl("ElectricityConversion")).Text.Equals(""))
                        miss = miss + "ElectricityConversion \\n";
                    if (((TextBox)DetailsView1.FindControl("GasConversion")).Text.Equals(""))
                        miss = miss + "GasConversion \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddress")).Text.Equals(""))
                        miss = miss + "SupplyAddress \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddressSuburb")).Text.Equals(""))
                        miss = miss + "SupplyAddressSuburb \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddressState")).Text.Equals(""))
                        miss = miss + "SupplyAddressState \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddressPostcode")).Text.Equals(""))
                        miss = miss + "SupplyAddressPostcode \\n";
                    if (((TextBox)DetailsView1.FindControl("TenantOwner")).Text.Equals(""))
                        miss = miss + "TenantOwner \\n";
                    if (((TextBox)DetailsView1.FindControl("Elec")).Text.Equals(""))
                        miss = miss + "Elec \\n";
                    if (((TextBox)DetailsView1.FindControl("Gas")).Text.Equals(""))
                        miss = miss + "Gas \\n";
                    if (((TextBox)DetailsView1.FindControl("ExistingTRUEnergyCustomer")).Text.Equals(""))
                        miss = miss + "ExistingTRUEnergyCustomer \\n";

                    if (miss.Equals(""))
                        DetailsView1.UpdateItem(false);
                    else
                    {
                        MessageBox("The following fields must be completed:\\n" + miss);
                        DetailsView1.UpdateItem(false);
                    }
                }
            }
            else
                DetailsView1.UpdateItem(false);
        }

        protected void insertUser(string insertcommand)
        {
            string connectionString = null;
            System.Configuration.ConnectionStringSettings connString = System.Configuration.ConfigurationManager.ConnectionStrings["SQLServer2005DBConnectionString"];
            if (null != connString)
                connectionString = connString.ConnectionString;

            System.Data.SqlClient.SqlConnection connection = null;
            connection = new System.Data.SqlClient.SqlConnection(connectionString);
            connection.Open();
            System.Data.SqlClient.SqlCommand command;
            command = connection.CreateCommand();
            command.CommandText = insertcommand;
            command.ExecuteNonQuery();
            connection.Close();
        }

        private void MessageBox(string message)
        {
            if (!string.IsNullOrEmpty(message))
            {
                //this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alt1", "alert('" + message + "');", true);
            }
        }
    }
}